Golang flag.Uint() function example
package flag
Uint defines a uint flag with specified name(1st parameter), default value(2nd parameter), and usage string(3rd parameter). The return value is the address of a uint variable that stores the value of the flag.
Golang flag.Uint() function usage example
package main
import (
"flag"
"fmt"
"strconv"
)
func main() {
port := flag.Uint("port", 8080, "Port to listen. Default is 8080")
flag.Parse()
fmt.Println(flag.Lookup("port")) // print the Flag struct
fmt.Printf("Port number is %s\n ", strconv.Itoa(int(*port)))
}
Output :
&{port Port to listen. Default is 8080 8080 8080}
Port number is 8080
Reference :
Advertisement
Something interesting
Tutorials
+14.2k Golang : Chunk split or divide a string into smaller chunk example
+14.4k Golang : On enumeration
+9.6k Golang : Read file with ioutil
+10.6k Android Studio : Simple input textbox and intercept key example
+19.9k Golang : Accept input from user with fmt.Scanf skipped white spaces and how to fix it
+5.6k Unix/Linux : How to find out the hard disk size?
+24.6k Golang : How to print rune, unicode, utf-8 and non-ASCII CJK(Chinese/Japanese/Korean) characters?
+20.2k Golang : How to get struct tag and use field name to retrieve data?
+22.2k Golang : Securing password with salt
+4.9k Unix/Linux : secure copying between servers with SCP command examples
+35.1k Golang : Upload and download file to/from AWS S3
+12.3k Golang : Get month name from date example